Remember?
Register
Back

Templating

By Monkeymatt last edited on Saturday, May 20, 2006 at 1:11:02 pm by Monkeymatt. Page 9.

<< Prev123456789

Here is an example of how to use it:

Template file:
Code

<html>
<head>
<title>Test Page for Template</title>
<style type="text/css">
table{
border: solid 2px #000000;
}
</style>
</head>
<body>
{title}

<{lotsopeople}>

<table>
<tr><th colspan='2'>{maker}</th></tr>
<tr><th>Name</th><th>Note</th></tr>
<{notebook}>
<tr><td>{name}</td><td>{note}</td></tr>
<{/notebook}>
</table>
<div>&nbsp;</div>

<{/lotsopeople}>
<{anotherloop}>
<div>We Love Loops</div>
<{/anotherloop}>
</body>
</html>


Here is the php to make it dynamic: (assumes template file is stored as template.tpl in same folder, and the template class is already loaded)

PHP Code

<?php
$template
=new Template();
$template->add_file("template.tpl");
$template->base_title="<h1>MEMEMEMEMEMEMEMEME</h1>";
$template->set_section("lotsopeople");
$template->maker="Monkeymatt";
$template->set_section("notebook");
$template->name="Monkeymatt";
$template->note="Best Person in the World!";
$template->next_section_iteration();
$template->name="Someone";
$template->note="Rollerblader";
$template->next_section_iteration();
$template->name="Someone Else";
$template->note="Lego Guy";
$template->set_section("lotsopeople");
$template->next_section_iteration();
$template->maker="Classes";
$template->set_section("notebook");
$template->name="AP European History";
$template->note="Hard, time consuming class";
$template->next_section_iteration();
$template->name="Biology X";
$template->note="Slow, semi-interesting class";
$template->next_section_iteration();
$template->name="Spanish 2x";
$template->note="Es la clase de Espanol";
$template->next_section_iteration();
$template->name="Physics X";
$template->note="The BEST CLASS EVER";
$template->set_section("anotherloop");
$template->next_section_iteration();
?>




Here is what that would output:

Code

<html>
<head>
<title>Test Page for Template</title>
<style type="text/css">
table{
border: solid 2px #000000;
}
</style>
</head>
<body>
<h1>MEMEMEMEMEMEMEMEME</h1>



<table>
<tr><th colspan='2'>Matt Crane</th></tr>

<tr><th>Name</th><th>Note</th></tr>

<tr><td>Monkeymatt</td><td>Best Person in the World!</td></tr>

<tr><td>Someone</td><td>Rollerblader</td></tr>

<tr><td>Someone Else</td><td>Lego Guy</td></tr>


</table>
<div>&nbsp;</div>



<table>
<tr><th colspan='2'>Classes</th></tr>
<tr><th>Name</th><th>Note</th></tr>

<tr><td>AP European History</td><td>Hard, time consuming class</td></tr>


<tr><td>Biology X</td><td>Slow, semi-interesting class</td></tr>

<tr><td>Spanish 2x</td><td>Es la clase de Espanol</td></tr>

<tr><td>Physics X</td><td>The BEST CLASS EVER</td></tr>

</table>
<div>&nbsp;</div>


<div>We Love Loops</div>

</body>
</html>


That's it.

<< Prev123456789